﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum WaterType
{
	ShiRui,
	HCL,
	NaOh
}

public class DropperHat : MonoBehaviour 
{
	public DropperController controller;
	public float timer;

	RaycastHit hit;

	IEnumerator OnMouseDown()
	{
		Debug.Log ("xxx");
		timer = Time.time;

		Vector3 screenSpace = Camera.main.WorldToScreenPoint(transform.root.position);
		Vector3 offset = transform.root.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));

		while (Input.GetMouseButton (0)) {
			Vector3 curScreenSpace = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
			Vector3 curPosition = Camera.main.ScreenToWorldPoint (curScreenSpace) + offset;
			transform.root.position = curPosition;

			yield return new WaitForFixedUpdate ();
		}
	}

	void OnMouseUp()
	{
		if (Time.time - timer < 0.2f) {
			controller.Action ();
		}
	}
}
